﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using BaseLinQ.DataContex;

namespace Module
{
    public class PhanHoiLogic
    {
        string strConnectionString = ConfigurationSettings.AppSettings["ConnectString"];
        RBACDataContext db = null;
        /// <summary>
        /// Thêm mới 
        /// </summary>
        /// <param name="_objPhanHoi"></param>
        /// <returns></returns>
        public bool Insert(tbl_PhanHoi _objPhanHoi)
        {
            bool blnFalse = false;
            db = new RBACDataContext(strConnectionString);
            try
            {
                db.tbl_PhanHois.InsertOnSubmit(_objPhanHoi);
                db.SubmitChanges();
                blnFalse = true;
            }
            catch (Exception ex)
            {

            }
            db = null;
            return blnFalse;
        }
        /// <summary>
        /// Cap nhat thong tin phản hồi
        /// </summary>
        /// <param name="_objPhanHoiNew"></param>
        /// <returns></returns>
        public bool Update(tbl_PhanHoi _objPhanHoiNew)
        {
            bool blnRes = false;
            db = new RBACDataContext(strConnectionString);
            try
            {
                tbl_PhanHoi objTaiNguyenOld = (from m in db.tbl_PhanHois
                                       where m.pk_iPhanHoiID == _objPhanHoiNew.pk_iPhanHoiID
                                                 select m).FirstOrDefault<tbl_PhanHoi>();
                if (objTaiNguyenOld != null && objTaiNguyenOld.pk_iPhanHoiID > 0)
                {
                    objTaiNguyenOld.sTieuDe = _objPhanHoiNew.sTieuDe;
                    db.SubmitChanges();
                    blnRes = true;
                }
            }
            catch (Exception ex)
            {
              
            }
            db = null;
            return blnRes;
        }
    }
}
